package com.yangoxix.lovegoing.mapper;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yangoxix.lovegoing.pojo.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface UserMapper extends BaseMapper<User> {
    @Select("select * from lovegoing.user where email = #{email}")
    User selectByEmail(@Param("email") String email);

    @Select("select COUNT(*) from user where username = #{username} limit 1")
    boolean isUserExisted(@Param("username") String username);

    @Select("select COUNT(*) from user where email = #{email} limit 1")
    boolean isUserExistedViaEmail(@Param("email") String email);

    @Select("select mask from user where username = #{username}")
    int selectMaskByUsername(@Param("username") String username);

    @Update("update user set mask = #{mask} where username = #{username}")
    void updateMaskByUsername(@Param("username") String username, @Param("mask") int mask);

    @Update("update user set motto = #{motto} where username = #{username}")
    void updateMottoByUsername(@Param("username") String username, @Param("motto") String motto);

    @Select("select photo from user where username = #{username}")
    String getPortraitByUsername(@Param("username") String username);

    @Select("select motto from user where username = #{username}")
    String getMottoByUsername(@Param("username") String username);

    @Select("select not isnull(photo) from user where username = #{username}")
    boolean isPortraitPresentByUsername(@Param("username") String username);
}
